
package core;

import java.util.*;

/**
 *
 * @author Raed Shomali
 */
public class COINCOMOUnit 
{
    String name = "" ;
    
    long unitID = 0 ;

    long parentID = 0 ;
    
    HashMap<Long , COINCOMOUnit> listOfSubUnits = new HashMap<Long , COINCOMOUnit>() ;

    public void addSubUnit( COINCOMOUnit unit )
    {
        listOfSubUnits.put( unit.getUnitID() , unit ) ;
    }
    
    /**
     * 
     * @return the id of the parent unit.
     */
    public long getParentID()
    {
        return parentID;
    }

    public void setParentID( long parentID )
    {
        this.parentID = parentID;
    }

    public long getFinalSLOC()
    {
        long sum = 0;
        
        Iterator<COINCOMOUnit> it = getListOfSubUnits().values().iterator() ;
        
        while( it.hasNext() )
        {
            COINCOMOUnit unit = (COINCOMOUnit)it.next() ;
            
            sum += unit.getFinalSLOC() ;
        }
        
        return sum ;
    }
    
    public float getCost()
    {
        float cost = 0;
        
        Iterator<COINCOMOUnit> it = getListOfSubUnits().values().iterator() ;
        
        while( it.hasNext() )
        {
            COINCOMOUnit unit = (COINCOMOUnit)it.next() ;
            
            cost += unit.getCost() ;
        }
        
        return cost ;
    }
    
    public float getStaff()
    {
        float staff = 0;
        
        Iterator<COINCOMOUnit> it = getListOfSubUnits().values().iterator() ;
        
        while( it.hasNext() )
        {
            COINCOMOUnit unit = (COINCOMOUnit)it.next() ;
            
            staff += unit.getStaff() ;
        }
        
        return staff ;
    }
    
    public float getTotalEffort()
    {
        float effort = 0;
        
        Iterator<COINCOMOUnit> it = getListOfSubUnits().values().iterator() ;
        
        while( it.hasNext() )
        {
            COINCOMOUnit unit = (COINCOMOUnit)it.next() ;
            
            effort += unit.getTotalEffort() ;
        }
        
        return effort ;
    }
    
    public float getTotalSchedule()
    {
        float schedule = 0;
        
        Iterator<COINCOMOUnit> it = getListOfSubUnits().values().iterator() ;
        
        while( it.hasNext() )
        {
            COINCOMOUnit unit = (COINCOMOUnit)it.next() ;
            
            schedule += unit.getTotalSchedule() ;
        }
        
        return schedule ;
    }
    
    /**
     * 
     * @return the name of the unit as a String.
     */
    public String getName()
    {
        return name;
    }

    /**
     * 
     * @param name sets the Units Name
     */
    public void setName( String name )
    {
        this.name = name;
    }

    /**
     * 
     * @param unitID sets the Unit's ID
     */
    public void setUnitID( long unitID )
    {
        this.unitID = unitID;
    }
    
    /**
     * 
     * @return the unit id of type long
     */
    public long getUnitID()
    {
        return unitID;
    }

    /**
     * 
     * @return the Hash Map that contains the Sub Units of the current unit
     */
    public HashMap<Long , COINCOMOUnit> getListOfSubUnits()
    {
        return listOfSubUnits;
    }
}
